package com.atguigu.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/***
 * MyThreadPoolConfig 自己的线程池配置类
 *
 *
 * properties.getCorePoolSize(),
 * properties.getMaxPoolSize(),
 * properties.getKeepAliveTime(),
 * 是从配置文件中获取与属性
 *
 *
 * ThreadPoolConfigProperties properties 相当于properties文件
 * properties.getCorePoolSize()就是配置文件中的某一个参数
 * */

@Configuration
public class MyThreadPoolConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties properties) {
        return new ThreadPoolExecutor(
                properties.getCorePoolSize(),
                properties.getMaxPoolSize(),
                properties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10000),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
